/*
 * @Author: 李文杰
 * @Date: 2023-03-24 16:55:16
 * @LastEditors: 李文杰
 * @LastEditTime: 2023-03-27 13:30:45
 * @Description: 请填写简介
 */
const SUCCESS = 200;
const ERROR = 401;
class ServerResponse {
  constructor(status, msg, data) {
    this.status = status;
    this.msg = msg;
    this.data = data;
  }
  static createBySuccess() {
    return new ServerResponse(SUCCESS);
  }
  static createBySuccessMsg(msg = '请求成功') {
    return new ServerResponse(SUCCESS, msg, null);
  }
  static createBySuccessData(data) {
    return new ServerResponse(SUCCESS, null, data);
  }
  static createBySuccessMsgAndData(msg = '请求成功', data) {
    return new ServerResponse(SUCCESS, msg, data);
  }

  static createByError() {
    return new ServerResponse(ERROR);
  }
  static createByErrorMsg(msg = '请求错误') {
    return new ServerResponse(ERROR, msg, null);
  }
  static createByErrorData(data) {
    return new ServerResponse(ERROR, null, data);
  }
  static createByErrorMsgAndData(msg = '请求错误', data) {
    return new ServerResponse(ERROR, msg, data);
  }
}

module.exports = ServerResponse;
